const { DataTypes } = require("sequelize");

module.exports = (sequelize, Sequelize) => {
  const User = sequelize.define("user", {
    name: DataTypes.TEXT,
    favoriteColor: {
      type: DataTypes.TEXT,
      defaultValue: "green",
    },
    age: DataTypes.INTEGER,
    cash: DataTypes.INTEGER,
    isAdmin: {
      type: DataTypes.BOOLEAN,
      defaultValue: false,
    },
  });
  (async () => {
    await sequelize.sync({ force: true });
    const jane = await User.create({ name: "Jane" });
    await User.create({ name: "Jane2" });
    await User.create({ name: "Jane3" });
    await User.create({
      name: "admin",
      isAdmin: true,
    });
    jane.set({
      name: "Ada",
      favoriteColor: "blue",
    });
    // console.log(JSON.stringify(adminUser, null ,2)); // 这样最好!
  })();
  return User;
};
